
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/19/2011 02:28:50
-- Generated from EDMX file: C:\Users\Lucas\Documents\Visual Studio 2010\Projects\projeto-mvc-puc\projeto-mvc-puc\Models\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Database];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PessoaTelefone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TelefoneSet] DROP CONSTRAINT [FK_PessoaTelefone];
GO
IF OBJECT_ID(N'[dbo].[FK_EnderecoPessoa]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PessoaSet] DROP CONSTRAINT [FK_EnderecoPessoa];
GO
IF OBJECT_ID(N'[dbo].[FK_PessoaContato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContatoSet] DROP CONSTRAINT [FK_PessoaContato];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[PessoaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PessoaSet];
GO
IF OBJECT_ID(N'[dbo].[TelefoneSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TelefoneSet];
GO
IF OBJECT_ID(N'[dbo].[EnderecoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EnderecoSet];
GO
IF OBJECT_ID(N'[dbo].[ContatoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContatoSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'PessoaSet'
CREATE TABLE [dbo].[PessoaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Tipo] nvarchar(max)  NULL,
    [Nome] nvarchar(max)  NULL,
    [CPF] nvarchar(max)  NULL,
    [Idade] int  NULL,
    [CNPJ] nvarchar(max)  NULL,
    [RazaoSocial] nvarchar(max)  NULL,
    [Endereco_Id] int  NOT NULL
);
GO

-- Creating table 'TelefoneSet'
CREATE TABLE [dbo].[TelefoneSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Numero] nvarchar(max)  NULL,
    [Tipo] nvarchar(max)  NULL,
    [Pessoa_Id] int  NOT NULL
);
GO

-- Creating table 'EnderecoSet'
CREATE TABLE [dbo].[EnderecoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Rua] nvarchar(max)  NULL,
    [Numero] int  NULL,
    [Complemento] nvarchar(max)  NULL,
    [Bairro] nvarchar(max)  NULL
);
GO

-- Creating table 'ContatoSet'
CREATE TABLE [dbo].[ContatoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Assunto] nvarchar(max)  NULL,
    [Arquivo] nvarchar(max)  NULL,
    [Mensagem] nvarchar(max)  NULL,
    [Status] nvarchar(max)  NULL,
    [Pessoa_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'PessoaSet'
ALTER TABLE [dbo].[PessoaSet]
ADD CONSTRAINT [PK_PessoaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TelefoneSet'
ALTER TABLE [dbo].[TelefoneSet]
ADD CONSTRAINT [PK_TelefoneSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EnderecoSet'
ALTER TABLE [dbo].[EnderecoSet]
ADD CONSTRAINT [PK_EnderecoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContatoSet'
ALTER TABLE [dbo].[ContatoSet]
ADD CONSTRAINT [PK_ContatoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Pessoa_Id] in table 'TelefoneSet'
ALTER TABLE [dbo].[TelefoneSet]
ADD CONSTRAINT [FK_PessoaTelefone]
    FOREIGN KEY ([Pessoa_Id])
    REFERENCES [dbo].[PessoaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PessoaTelefone'
CREATE INDEX [IX_FK_PessoaTelefone]
ON [dbo].[TelefoneSet]
    ([Pessoa_Id]);
GO

-- Creating foreign key on [Endereco_Id] in table 'PessoaSet'
ALTER TABLE [dbo].[PessoaSet]
ADD CONSTRAINT [FK_EnderecoPessoa]
    FOREIGN KEY ([Endereco_Id])
    REFERENCES [dbo].[EnderecoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EnderecoPessoa'
CREATE INDEX [IX_FK_EnderecoPessoa]
ON [dbo].[PessoaSet]
    ([Endereco_Id]);
GO

-- Creating foreign key on [Pessoa_Id] in table 'ContatoSet'
ALTER TABLE [dbo].[ContatoSet]
ADD CONSTRAINT [FK_PessoaContato]
    FOREIGN KEY ([Pessoa_Id])
    REFERENCES [dbo].[PessoaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PessoaContato'
CREATE INDEX [IX_FK_PessoaContato]
ON [dbo].[ContatoSet]
    ([Pessoa_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------